<?php
	session_start();
	header("Content-type:text/html;charset=utf-8");

	$conn = 	$conn = mysqli_connect('127.0.0.1','root','pwd','admin',3306);//链接数据库('localhost','hotel','vw8jj2','login',3308);
	mysqli_set_charset($conn,'utf8'); //设定字符集

	$name=$_POST['name'];
	$pwd=$_POST['pwd'];
	$pwdconfirm=$_POST['pwdconfirm'];
	$yzm=$_POST['yzm'];

	$sql_select="select id,admin_name,password from admin where admin_name= ?"; 

	$stmt=mysqli_prepare($conn,$sql_select); 
	mysqli_stmt_bind_param($stmt,'s',$name);
	mysqli_stmt_execute($stmt);
	$result=mysqli_stmt_get_result($stmt);
	$row=mysqli_fetch_assoc($result);

	if ($name !=$row['admin_name']){
		if ($_REQUEST['yzm'] != $_SESSION['authcode']) {
				echo "<script>alert('验证码错误，请重新输入');location='admin_registered.html'</script>";
	 			exit;
			}else{
				$insert_sql="insert into admin(admin_name,password)values(? , ? )";

				$stmt=mysqli_prepare($conn,$insert_sql);

				mysqli_stmt_bind_param($stmt,'ss',$name,$pwd);

				$result_insert=mysqli_stmt_execute($stmt);
				echo "<script>alert('您已注册成功，返回登录');location='admin_login.html'</script>";
	 			exit;
			}
	}else{
		echo "<script>alert('您输入的用户名已存在,请重新注册！');location='admin_registered.html'</script>";
	 	exit;
	}


 